<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style> 
        div{
            width:300px;
            height:300px;
            background:#f00;
            margin:500px auto;
            position:relative;
        }
        h1{
            width:50px;
            height:50px;
            background:#0a0;
            position:absolute;
            margin:0;
            top:100px;
            left:100px;
        }
    </style>
</head>
<body>
    <div>
        <h1>哈</h1>
    </div>
    <script src="jquery.js"></script>
    <script>
        //获取div距离边线的距离
        console.log($('div').offset());
        //获取h1距离div边线的距离
        console.log($('h1').position());
    </script>
</body>
</html>